{% extends 'classroom-manage/layout.html.twig' %}

{% block title %}{{ setting('classroom.name')|default("site.default.classroom"|trans) }}{{'classroom.manage'|trans}} - {{ parent() }}{% endblock %}

{% set side_nav = 'main' %}

{% block main %}
{% set unsetted = "" %}
<div class="panel panel-default" role="classroom-manage-index">
  <div class="panel-body">
    {{ web_macro.flash_messages() }}
    <div class="row">
      <div class="col-md-4">
        <div class="well">
          <h4>{{'classroom.set'|trans}}</h4>
          <table class="table">
            <tr>
              <td>{{'classroom.about'|trans}}</td>
              {% if not classroom.about %}
                <td>
                  <a class="btn btn-danger btn-xs pull-right" href="{{path('classroom_manage_set_info',{id:classroom.id})}}">
                    {{'classroom.unset'|trans}} <i class="glyphicon glyphicon-circle-arrow-right"></i>
                  </a>
                </td>
                {% set unsetted = unsetted ~ ',' ~ 'classroom.about'|trans %}
              {% else %}
                <td>
                  <i class="glyphicon glyphicon-ok-sign pull-right color-success"></i>
                </td>
              {% endif %}
            </tr>
            <tr>
              <td>{{'classroom.small_picture'|trans}}</td>
              {% if not classroom.smallPicture %}
                <td>
                  <a class="btn btn-danger btn-xs pull-right" href="{{path('classroom_manage_set_picture',{id:classroom.id})}}">
                    {{'classroom.unset'|trans}} <i class="glyphicon glyphicon-circle-arrow-right"></i>
                  </a>
                </td>
                {% set unsetted = unsetted ~ ',' ~ 'classroom.small_picture'|trans %}
              {% else %}
                <td>
                  <i class="glyphicon glyphicon-ok-sign pull-right color-success"></i>
                </td>
              {% endif %}
            </tr>
            <tr>
              <td>{{'classroom.price'|trans}}</td>
              <td>
                <a class="btn btn-info btn-xs pull-right" href="{{path('classroom_manage_set_price',{id:classroom.id})}}">
                  {% if setting('coin.coin_enabled') and setting('coin.price_type') == 'Coin' %}
                    {{classroom.price * setting('coin.cash_rate') }} {{setting('coin.coin_name')}}
                    {% if classroom.price * setting('coin.cash_rate')  == 0 %}
                      {% set unsetted = unsetted ~ ',' ~ 'classroom.price'|trans %}
                    {% endif %}
                  {% else %}
                    {{ classroom.price }}{{'site.currency.CNY'|trans}}
                    {% if classroom.price == 0 %}
                      {% set unsetted = unsetted ~ ',' ~ 'classroom.price'|trans %}
                    {% endif %}
                  {% endif %}
                  <i class="glyphicon glyphicon-circle-arrow-right"></i>
                </a>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="col-md-4">
        <div class="well">
          <h4>{{'classroom.course'|trans}}</h4>
          <table class="table">
            <tr>
              <td>{{'classroom.course_num'|trans}}</td>
              <td>
                <a class="btn btn-{% if classroom.courseNum > 0 %}info{% else %}danger{% endif %} btn-xs pull-right" href="{{ path('classroom_manage_courses', {id:classroom.id}) }}">
                  {{classroom.courseNum|default(0)}} <i class="glyphicon glyphicon-circle-arrow-right"></i>
                </a>
              </td>
              {% if classroom.courseNum == 0 %}
                {% set unsetted = unsetted ~ ',' ~ 'classroom.course'|trans %}
              {% endif %}
            </tr>
            <tr>
              <td>{{'classroom.tash_num'|trans({'%taskName%':setting('course.task_name')|default('admin.setting_course.task'|trans)})}}</td>
              <td><span class="label label-default pull-right">{{classroom.lessonNum}}</span></td>
            </tr>
          </table>
        </div>
      </div>
      <div class="col-md-4">
        <div class="well">
          <h4>{{'classroom.student'|trans}}</h4>
          <table class="table">
            <tr>
              <td>{{'classroom.student_num'|trans}}</td>
              <td>
                <a class="btn {% if (classroom.studentNum) > 0 %}btn-info{% else %}btn-danger{% endif %} btn-xs pull-right" href="{{ path('classroom_manage_students', {id:classroom.id}) }}">
                  {{classroom.studentNum}} <i class="glyphicon glyphicon-circle-arrow-right"></i>
                </a>
              </td>
            </tr>
            <tr>
              <td>{{'classroom.auditor_num'|trans}}</td>
              <td>
                <a class="btn {% if (classroom.auditorNum) > 0 %}btn-info{% else %}btn-danger{% endif %} btn-xs pull-right" href="{{ path('classroom_manage_aduitor', {id:classroom.id}) }}">
                  {{classroom.auditorNum}} <i class="glyphicon glyphicon-circle-arrow-right"></i>
                </a>
              </td>
            </tr>
          </table>
        </div>
      </div>
    </div>
    {% if classroom.status == "published" %}
      <hr>
      <div class="row">
        <div class="col-md-6">
          <h4>{{'classroom.study_status'|trans({'%name%':setting('classroom.name')|default('classroom'|trans)})}}</h4>
          <table class="table">
            <thead>
              <th></th>
              <th>{{'classroom.yesterday'|trans}}</th>
              <th>{{'classroom.today'|trans}}</th>
            </thead>
            <tr>
              <td>{{'classroom.total_student_num'|trans}}</td>
              <td>{{yestodayAllCount}}</td>
              <td>{{allCount}}</td>
            </tr>
            <tr>
              <td>{{'classroom.formal_student_num'|trans}}</td>
              <td>{{yestodayStudentCount}}</td>
              <td>{{studentCount}}</td>
            </tr>
            <tr>
              <td>{{'classroom.task_finish_num'|trans({'%taskName%':setting('course.task_name')|default('admin.setting_course.task'|trans)})}}</td>
              <td>{{yesterdayFinishedTaskNum}}</td>
              <td>{{todayFinishedTaskNum}}</td>
            </tr>
            <tr>
                <td>{{'classroom.add_thread_num'|trans}}</td>
                <td>{{yesterdayThreadCount}}</td>
                <td>{{todayThreadCount}}</td>
            </tr>
          </table>
        </div>

        <div class="col-md-6 reviews">
          <h4>{{'classroom.latest_review'|trans}}</h4>
          <br>
          {% if reviews%}
            {% for review in reviews %}
              {% if loop.index <= 4 %}
                <div class="media">
                  <div class="pull-left">
                    <span class="class-name">{{reviewUsers[review.userId].nickname}}</span>
                  </div>
                  <div class="media-body">
                    <div class="stars-{{ (review.rating)|number_format }}"></div>
                    &nbsp;&nbsp;&nbsp;&nbsp;<time>{{review.createdTime|smart_time}}</time>
                    <button class="btn btn-success btn-xs" data-toggle="modal" data-target="#modal" data-url="{{path('message_create', {toId:reviewUsers[review.userId].id})}}" style="float:right;">{{'message'|trans}}</button>
                  </div>
                  <p>{{ review.content|plain_text(40) }}</p>
                </div>
              {% endif %}
            {% endfor %}
          {% else %}
            <div class="empty">{{'classroom.reviews_empty'|trans({'%name%':setting('classroom.name')|default('classroom'|trans)})}}</div>
          {% endif %}
        </div>
      </div>
      <hr>
    {% endif %}
  </div>
</div>
{% endblock %}
